﻿var controller = this.lookupController();
var viewStatus = controller.analysis().status;
var vm = this.lookupViewModel();

if (viewStatus == 'approval') {
    var fieldNameList = ['costCenter', 'prs', 'prsAmounts', 'pos', 'posAmounts', 'email'];

    Ext.each(fieldNameList, function (field) {
        ref[field].setAllowBlank(true);
    });
}
if (formData.approvalInfo) {
    formData.approvalInfo.approverDesc = '';
}
ref.attachment.hide();
var activity = "";
//查询流程节点
Ext.PAIRest.request({
    url: 'formActivity/currentProcInst',
    ns: PAI.application.userServerUrl,
    method: "POST",
    async: false,
    data: {
        "destInstId": PAI.Global.getUrlData('destInstId') || '',
        "procInstId": PAI.Global.getUrlData('procInstId') || ''
    },
    success: function (data) {
        if (data.currentActivitys.length > 0) {

            var destInstId = PAI.Global.getUrlData('destInstId');
            var currentActivity = data.currentActivitys.filter(function (item) {
                return item.empList.filter(function (item2) {
                    return item2.destInstId == PAI.Global.getUrlData('destInstId');
                }).length > 0;
            });

            if (currentActivity.length) {
                activity = currentActivity[0].activityName;
            }
        }
    },
    failure: function (jsondata) {
        console.log(jsondata);
    }
});
vm.set('NebulogyForm.activity', activity);
vm.set('NebulogyForm.pushStatus', '0');
vm.set('NebulogyForm.state', 'on boarding');


if (viewStatus == 'launch') {
    Ext.PAIRest.request({
        url: 'orgEmployeeRel/listOrganizationObjByEmployeeObjId',
        method: 'POST',
        data: {
            bId: PAI.Global.getAccount().employee.id,
            objFields: [{
                exp: "$." + PAI.Global.getLanguage(),
                name: "displayName",
                type: "json"
            }],
            relFields: [{
                "name": "aId"
            }]
        },
        success: function (json) {
            if (!Ext.isEmpty(json.data)) {
                vm.set('NebulogyForm.applicantInfo.department', json.data[0].basic.displayName);
                vm.set('NebulogyForm.agencyInfo.agencyDepartment', json.data[0].basic.displayName);
            }
        }
    });
}


if (viewStatus == 'approval' || viewStatus == 'launch') {
    ref.approverCDSID.hide();
    ref.approverEmail.hide();

    if (activity.indexOf('Helpdesk') != -1) {
        ref.approverCDSID.show();
        ref.approverEmail.show();

        if (formData.companyResourcesRequest.companyResources.cdsid == 0) {
            ref.approverCDSID.setAllowBlank(true);
            ref.approverCDSID.setDisabled(true);
        }

        if (formData.companyResourcesRequest.email == 'Neither') {
            ref.approverEmail.setAllowBlank(true);
            ref.approverEmail.setDisabled(true);
        }

    } else if (activity == 'Administration Department Head' || activity.startsWith('Access card application')) {

        ref.companyResources.setReadOnly(false);
        ref.newBundFloors.setReadOnly(false);

        Ext.each(ref.companyResources.items.items, function (ctr) {
            if (ctr.inputValue == 'cdsid' || ctr.inputValue == 'skypeAccount' || ctr.inputValue == 'jlrFamily' || ctr.inputValue == 'none_') {
                ctr.setDisabled(true);
            }
        });
    }
}
